
var gDefaultPage = "http://www.56qss.com/loading.html";
var gHideSelects = false;

function initPopUp(reload) {
    // Add the HTML to the body
    // Check if the dialog elements exist and create them if not
    if (!document.getElementById('popupContainer')) {
        $('<div id="popupContainer"></div>').html("<div id='layer_popTitle'><div id='popupTitle'></div>" +
            "<div id='popupClose'></div></div>" +
            '<iframe src="' + gDefaultPage +
            '" scrolling="auto" frameborder="0" id="popupFrame" name="popupFrame" width="100%" height="auto"></div>'
            ).hide().appendTo("body")

        if (!document.getElementById('popupMask')) {
            $('<div id="popupMask"><iframe /></div>').hide().appendTo("body"); //addClass($.browser.msie ? "popupMaskIE" : "popupMaskFF").
        }
        else { $('#popupMask').hide(); }
        // 设置的Click事件的“ X ”和“关闭”按钮
        $("#popupClose").click(function() { hidePopWin(reload); });

    }
    else {

        $('#popupContainer').html("<div id='layer_popTitle'><div id='popupTitle'></div>" +
            "<div id='popupClose'></div></div>" +
            '<iframe src="' + gDefaultPage +
            '" scrolling="auto" frameborder="0" id="popupFrame" name="popupFrame" width="100%" height="auto"></div>'
            );
        $('#popupMask').hide();
        $('#popupContainer').hide();
        // 设置的Click事件的“ X ”和“关闭”按钮
        $("#popupClose").click(function() { hidePopWin(); });
    }
}

function showPopWin(url, title, width, height,reload) {
    initPopUp(reload);

    var original = $(document.body);
    var dlm = $('#popupMask');
    var dlmw = Math.max($(window).width(), $(document).width());
    var dlmh = Math.max($(window).height(), $(document).height());
    dlm.width(dlmw).height(dlmh).css({ width: dlmw, height: dlmh }); ;
    $('#popupMask iframe').width(dlmw).height(dlmh).css({ width: dlmw, height: dlmh });
    //    var maskHeight = original.outerHeight();
    //    if (!maskHeight) {
    //        maskHeight = original.height();
    //    }
    //    dlm.height(maskHeight);


    var dl = $('#popupContainer');

    dl.width(width).height(height)

    if ($.browser.msie) {
        if (parseInt($.browser.version) > 6) {
            dlm.height($(window).height());
            dlm.css('position', 'fixed');
            dl.css('position', 'fixed');
            var dialogTop = Math.abs($(window).height() - height) / 2;
            dl.css('left', ($(window).width() - width) / 2);
            dl.css('top', (dialogTop >= 25) ? dialogTop : 25);
        }
        else {
            dlm.css({ height: "100%", left: 0, top: 0 });
            $('#popupClose').css('width', '20px');
            setPopWin(width, height);
            $(window).scroll(function() { setPopWin(width, height); });
            $(window).resize(function() { setPopWin(width, height); });
        }
    }
    else {
        dlm.css('position', 'fixed');
        dl.css('position', 'fixed');
        var dialogTop = Math.abs($(window).height() - height) / 2;
        dl.css('left', ($(window).width() - width) / 2);
        dl.css('top', (dialogTop >= 25) ? dialogTop : 25);
    }

    $('#popupFrame').height(height - 28);
    $('#popupFrame').width(width);
    $('#popupTitle').width(width - 30);

    if (gHideSelects) {
        $("select").hide();
    }

    dl.fadeIn("show");
    dlm.fadeTo('slow', 0.2);

    if (title != null && title != "") {
        $("#popupTitle").html(title);
    }
    window.setTimeout("$('#popupFrame').attr('src','" + url + "');", 1000);

}

//窗口改变
function setPopWin(width, height) {
    var original = $(document.body);

    var dlm = $('#popupMask');
    var dl = $('#popupContainer');
    dlm.css('position', 'absolute');
    dlm.width($(window).width());
    var maskHeight = original.outerHeight();
    if (!maskHeight) {
        maskHeight = original.height();
    }
    dlm.height(maskHeight);
    //dlm.css('filter', 'alpha(opacity=20)');
    dl.css('position', 'absolute');
    var iescrollTop = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
    var dialogTop = (Math.abs($(window).height() - height) / 2) + iescrollTop;
    dl.css('left', ($(window).width() - width) / 2);
    dl.css('top', (dialogTop >= 25) ? dialogTop : 25);
}

function hidePopWin(reload) {
    if (gHideSelects) {
        $("select").show();
    }
    $('#popupContainer').fadeOut("slow", function() { $(this).hide(0); });
    $('#popupMask').fadeOut("normal", function() { $(this).hide(0); });

    if ($.browser.msie && $.browser.version == "6.0") {
        $(window).scroll(function() { });
        $(window).resize(function() { });
    }
    
    if(reload){
	    // 刷新调用主界面
	    window.location.reload();
	}
    
}

function setPopTitle() {
    return;
    if (window.frames["popupFrame"].document.title == null) {
        window.setTimeout("setPopTitle();", 10);
    } else {
        $("#popupTitle").html(window.frames["popupFrame"].document.title);
    }
}